#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <wait.h>
using namespace std;

int main()
{
    if(fork()==0)
    {
        //child
        while(1)
        {
            cout<<"I am child getpid:"<<getpid()<<"ppid:"<<getppid()<<endl;
            sleep(1);
        }
        exit(0);
    }
    //father 
    cout<<"I am father getpid:"<<getpid()<<"ppid:"<<getppid()<<endl;
    int status=0;
    int ret=waitpid(-1,&status,0);
    if(ret>0&&WIFEXITED(status))
    {
        cout<<"wait success exit code:"<<WEXITSTATUS(status)<<endl;
    }
    else if(ret>0)
    {
        cout<<"exit signal:"<<(status&0x7F)<<" core dump:"<<((status>>7)&1)<<endl;
    }
    
    return 0;
}
